package net.noday.web.util;

import java.io.FileOutputStream;
import java.io.IOException;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("/file")
public class FileUploadController {

	@RequestMapping(value="upload", method=RequestMethod.POST)
	public String upload(@RequestParam()MultipartFile file) {
		if (!file.isEmpty()) {
			byte[] bytes = null;
			try {
				bytes = file.getBytes();
			FileOutputStream fos = new FileOutputStream("e:/"+file.getOriginalFilename());
			fos.write(bytes);
			return "/ok";
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return "";
	}
}
